import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class ChinAz
{
    public static void main(String[] args)
    {
        while(true)
        {
            int i;
            String path = null;
            int name = 1;
            @SuppressWarnings("resource")
            Scanner scan = new Scanner(System.in);
            System.out.print("input_page:");
            int a = scan.nextInt();
            for(i=1;i<=a;i++)
            {
                if(i==1)
                {
                    path = "https://sc.chinaz.com/tupian/rentiyishu.html";
                }
                else
                {
                    path = "https://sc.chinaz.com/tupian/rentiyishu_"+i+".html";
                }
//							System.out.println(path);
                FileOutputStream outputStream = null;
                InputStream inputStream = null;
                try
                {
                    URL url = new URL(path);
                    Document document = Jsoup.parse(url, 30000);
//									System.out.println(document);
                    Elements elements = document.getElementsByClass("picblock");
                    for(Element element : elements)
                    {
                        String href = element.child(0).child(0).attr("href");
//											System.out.println("https:"+href);
                        URL hrefUrl = new URL("https:"+href);
                        Document document1 = Jsoup.parse(hrefUrl, 30000);
                        Elements elements1 = document1.getElementsByClass("imga");
                        for(Element element1 : elements1)
                        {
                            String imgSrc = element1.child(0).child(0).attr("src");
//									System.out.println("https:"+imgSrc);
                            URL imgsrcUrl = new URL("https:"+imgSrc);
                            URLConnection connection = imgsrcUrl.openConnection();
                            inputStream = connection.getInputStream();
                            String outFile = "F:\\temp\\"+name+".jpg";
                            name++;
                            outputStream = new FileOutputStream(outFile);
                            byte[] bytes = new byte[1024];
                            int len = 0;
                            while((len=inputStream.read(bytes))!=-1)
                            {
                                outputStream.write(bytes, 0, len);
                            }
                            System.out.println("Down_comp!!!");
                        }

                    }
                }
                catch(IOException e)
                {
                    e.printStackTrace();
                }
                finally
                {
                    try
                    {
                        inputStream.close();
                        outputStream.close();
                    }
                    catch(IOException e)
                    {
                        e.printStackTrace();
                    }
                }

            }

            }
        }

    }